package com.eportal.service;
import com.alibaba.fastjson.JSONObject;
import com.eportal.action.background.TKeysAction;
import com.eportal.domain.Sysopt;
import com.eportal.domain.TKeys;
import com.eportal.domain.TLock;
import com.eportal.domain.TUsers;
import com.eportal.entity.TKeysEntity;
import com.eportal.entity.TLocksEntity;
import com.eportal.entity.TUsersEntity;
import com.eportal.params.background.TKeys.TKeyParam;
import com.eportal.vo.controller.background.tkeys.TKeyListVO;
import com.framework.jqgrid.JqGridPager;
import com.framework.jqgrid.PageEntity;
import com.github.pagehelper.PageInfo;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface TKeysService extends BaseService<TKeysEntity> {

	List<Map<String, Object>> list(String sql, JqGridPager jqGridPager);

	TKeys get(Long id);

	TKeys getByWhere(String where);

    void delete(Long id);

    void update(TKeys tKeys) throws Exception;

    void delete(List<Long> ids);

    void add(TKeys tKeys) throws Exception;

    Map<String, Object> addMethod(TKeys tKeys);

    Map<String, Object> updateMethod(TKeys tKeys);

	Map<String, Object> deleteMethod(String param_ids);

	Map<String, Object> changeKeysStatusMethod(String sid, String status, String validity, TUsers tUser);

	Map<String, Object> SyncTo(TUsers tUsers, List<TLock> list, String validityDate, String agtCode, Date startTime);

	Map<String, Object> syncTo( TUsers tUser, List<TLock> lockList, String apiValidityDate, String agtCode,Date localValidDate, Date startTime);

	Map<String, Object> syncTo( String userid,String tel,String pid, Date apiValidityDate, String agtCode,Date localValidDate,Date startTime);


	Map<String, Object> syncTo ( String userid,String tel,List<String> pidList,  Date apiValidityDate, String agtCode,Date localValidDate,Date startTime);

	TKeys getTKeys(String userId, String string);

	List<Map<String, Object>> listPageApp(String where, int beginNum, int endNum,String type);

	int countSizeApp(String pageAppWhere);

	/**
	 * 硬件更换，在硬件损坏等情况下，社区可以更换设备
	 * @param sid
	 * @param newSid
	 * @param communityId
	 * @param installer
	 * @param sysopt 			当前用户
	 * @throws Exception
	 */
	void change(String sid, String newSid, String communityId,Long installer,Sysopt sysopt) throws Exception;

	List page4Prolong(String agtCode, String communityId, String next_sid);

//todo --------------------------------------------------------------------------------------------------------------------

	/**
	 * 钥匙同步
	 * @author Saber
	 * @Date 2017/8/14 上午9:17
	 * @param tUsersEntity		TUsersEntity 对象
	 * @param list				TLocksEntity list
	 * @param validityDate		向开放平台申请钥匙的有效期
	 * @param agtCode			合作方编码
	 * @param startTime			钥匙的开始有效时间
	 * @see TKeysService#SyncTo(TUsers, List, String, String, Date)
	 * @return
	 */
	JSONObject SyncTo(TUsersEntity tUsersEntity, List<TLocksEntity> list, String validityDate, String agtCode, Date startTime);

	/**
	 * 钥匙同步
	 * @author Saber
	 * @Date 2017/8/14 上午9:29
	 * @param tUsersEntityr		TUsersEntity 对象
	 * @param lockList			TLocksEntity list
	 * @param apiValidityDate	向开放平台申请钥匙的有效期
	 * @param agtCode			合作方编码
	 * @param localValidDate 	本地数据库存储的有效期
	 * @param startTime			钥匙的开始有效时间
	 * @see TKeysService#syncTo(TUsers, List, String, String, Date, Date)
	 * @return
	 */
	JSONObject syncTo(TUsersEntity tUsersEntityr, List<TLocksEntity> lockList, String apiValidityDate, String agtCode,Date localValidDate, Date startTime);

	/**
	 * 钥匙管理列表接口
	 * @author Saber
	 * @Date 2017/8/14 上午11:18
	 * @param pageEntity		分页对象
	 * @param param				查询参数
	 * @param user				当前用户
	 * @param userRole			当前用户userRole
	 * @see TKeysAction#page()
	 * @return
	 */
	PageInfo<TKeyListVO> queryForPage(PageEntity pageEntity, TKeyParam param, Sysopt user, int userRole);

	/**
	 * 修改钥匙状态或有效期
	 * @author Saber
	 * @Date 2017/8/14 下午6:02
	 * @param sId			sId
	 * @param status		状态		默认,0正常，1停用,2:设备被回收（永久禁用）
	 * @param validity		有效期
	 * @param user			当前用户
	 * @param userRole		当前用户userRole
	 * @see TKeysService#changeKeysStatusMethod(String, String, String, TUsers)
	 * @return
	 */
	JSONObject changeKeys(Long sId, String status, String validity, Sysopt user, int userRole);
}
